package com.xfatm.killer.util;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by wenjie on 2018/3/14.
 */

public class SharedPreferencesUtils {


    public static void saveSet(Context mContext, String name, Set<String> set) {
        SharedPreferences sp = mContext.getSharedPreferences("killer", Context.MODE_PRIVATE |Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putStringSet(name,set);
        editor.commit();
    }

    public static Set<String> readSet(Context mContext,String name) {
        SharedPreferences sp = mContext.getSharedPreferences("killer", Context.MODE_PRIVATE |Context.MODE_MULTI_PROCESS);
        return sp.getStringSet(name, new HashSet<String>());
    }

    public static void save(Context mContext,String name, String value) {
        SharedPreferences sp = mContext.getSharedPreferences("killer", Context.MODE_PRIVATE |Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(name, value);
        editor.commit();
    }

    public static String read(Context mContext,String name) {
        SharedPreferences sp = mContext.getSharedPreferences("killer", Context.MODE_PRIVATE |Context.MODE_MULTI_PROCESS);
        return sp.getString(name, "");
    }

    public static void saveBooleanForEnable(Context mContext,String name, boolean value) {
        SharedPreferences sp = mContext.getSharedPreferences("enable", Context.MODE_PRIVATE |Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(name, value);
        editor.commit();
    }

    public static boolean readBooleanForEnable(Context mContext,String name) {
        SharedPreferences sp = mContext.getSharedPreferences("enable", Context.MODE_PRIVATE |Context.MODE_MULTI_PROCESS);
        return sp.getBoolean(name, false);
    }

}
